package gs.wicket.app.product;

import gs.wicket.app.base.BasePage;
import gs.wicket.app.index.IndexPage;
import gs.wicket.app.session.Address;
import gs.wicket.app.session.Cart;

import java.util.Arrays;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.CheckBoxMultipleChoice;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

public class Checkout extends ProductsPage {
	public Checkout() {

		List<String> cities = Arrays.asList("Sarajevo", "Tuzla","Mostar");

		
		Form form = new Form("form");
		add(form);
		add(new Label("checkout.title", getLangProperty("checkout.title")));
		add(new Label("checkout.subtitle", getLangProperty("checkout.subtitle")));
		
		final Address address = getCart().getBillingAddress();
		form.add(new TextField("street", new PropertyModel(address, "street")).setRequired(true));
		form.add(new TextField("zipcode", new PropertyModel(address,"zipcode")).setRequired(true));
		form.add(new DropDownChoice("city", new PropertyModel(address, "city"),cities).setRequired(true));
		address.setState("Bosnia&Herzegovina");
		form.add(new TextField("phonenumber", new PropertyModel(address,"phonenumber")).setRequired(true));
		form.add(new Label("checkout.address", getLangProperty("checkout.address")));
		form.add(new Label("checkout.zip", getLangProperty("checkout.zip")));
		form.add(new Label("checkout.city", getLangProperty("checkout.city")));
		form.add(new Label("checkout.phone", getLangProperty("checkout.phone")));
		
		
		form.add(new Link("cancel") {
			
			private static final long serialVersionUID = 1L;
			{
				add(new AttributeModifier("value", new Model(getLangProperty("checkout.cancel"))));
			}
			@Override
			public void onClick() {
				setResponsePage(IndexPage.class);
			}
		});
		form.add(new Button("order") {
			
			private static final long serialVersionUID = 1L;
			{
				add(new AttributeModifier("value", new Model(getLangProperty("checkout.order"))));
			}

			@Override
			public void onSubmit() {
				Cart cart = getCart();
				cart.getProducts().clear();
				setResponsePage(IndexPage.class);
			}
		});
	}
}
